package a_java_48_day.day7;
/**
 * Fibonacci数列
 */

import java.util.*;
public class Fibonacci数列 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int fiboBefore=0;
        int fiboAfter=1;
        int ans=0;
        while(n>fiboAfter){
            int tmp=fiboAfter;
            fiboAfter=fiboAfter+fiboBefore;
            fiboBefore=tmp;
        }
        ans=(fiboAfter-n)<(n-fiboBefore)?(fiboAfter-n):(n-fiboBefore);
        System.out.println(ans);
    }
}